package mina.forwhat.client;

import org.apache.log4j.Logger;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

public class Demo1ClientHandler extends IoHandlerAdapter {

	public static Logger logger = Logger.getLogger(Demo1ClientHandler.class);
	
	private long times;

	@Override
	public void messageReceived(IoSession session, Object message) throws Exception {
		String msg = message.toString();
		logger.info("客户端接收到的信息为：" + msg);
		times = System.currentTimeMillis() - times;
		
		logger.info("总消耗时间为：   ==============" +times);
	}

	@Override
	public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
		logger.error("客户端发生异常...", cause);
	}
	@Override
	public void messageSent(IoSession session, Object message) throws Exception {
		//session.close(true); //发送成功后主动断开与客户端的连接
		logger.info("服务端发送信息成功...");
		times = System.currentTimeMillis();
	}

	}



